<?php
/**
 * класс для вывода различной информации в раздел сообщества
 *
 * @author Горбачев Максим
 * @version 1.0
 */
class View_Community extends Service_Pager {
	
	public static function dispalyCommunity($arrCommunity, $arrArticle, $pageNum){
	echo '
	<div class="name_community">
				<div class="name_bottom">
					<div class="name_left">
						<div class="name_right">
							<div class="name_left_top">
								<div class="name_right_top">
									<div class="name_left_bottom">
										<div class="name_right_bottom">
											<img title="людей в сообществе" alt="людей в сообществе" src="' .  W_IMAGES . 'pictures/community/s_' . (isset($arrCommunity['avatar_path']) ? ($arrCommunity['ID_community'] . '.' . $arrCommunity['avatar_path']) : 'default.gif') . '" height="80" width="80" />
											<div class="name_right_info">
												<h2>' . $arrCommunity['name'] . '</h2>
												<div class="box_name_reiting">
													<span class="name_reiting">
														<span class="name_reiting_left">
															<span class="name_reiting_right">
																<a href="' . W_ABSPATH . 'community/users/' . $arrCommunity['ID_community'] . '" class="bg_ret" title="людей в сообществе">' . $arrCommunity['users_count'] . '</a>
															</span>
														</span>
													</span>
												</div>
												<ul id="name_menu">
													<li><a class="information" href="javascript:alert(\'' . $arrCommunity['description'] . '\');"><span class="name_icon_1"></span></a></li>
													<li><a class="all_article_comuunity" href="' .  W_ABSPATH . 'articles?idFolder=' . $arrCommunity['ID_community'] . '"><span class="name_icon_2"></span>Все статьи сообщества</a></li>
													<li><a class="k_stene" href="' . W_ABSPATH . 'community/' . $arrCommunity['ID_community'] . '/' . $pageNum . '/#comments"><span class="name_icon_3"></span>К стене</a></li>
												</ul>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>';
	
	
    View_Article::displayArticles($arrArticle, true);
	  if (sizeof($arrArticle))
	  	echo '<span class="all_statua_community"><a  href="' .  W_ABSPATH . 'articles?idFolder=' . $arrCommunity['ID_community'] . '">Все статьи сообщества</a></span>';
	}
  
  /**
   * выводит список сообществ
   */
  public static function displayAllCommunity(array $arrCommunity){
	  $communitySize = sizeof($arrCommunity);
	  for ($num = 0; $num < $communitySize; $num++){
	  	echo '
	  	<table border="1">
	  		<tr>
	  			<td rowspan="3">';
	  				echo '
	  				<a href="' . W_ABSPATH . 'community/' . $arrCommunity[$num]['ID_community'] . '">
	  				<img src="' .  W_IMAGES . 'pictures/community/vs_';
		  				if ($arrCommunity[$num]['avatar_path'] != NULL)
		  					echo $arrCommunity[$num]['ID_community'] . '.' . $arrCommunity[$num]['avatar_path'];
		  				else echo 'default.png';
			  				echo 
	  				'"/>
	  				</a>';
	  			echo '
	  			</td>
	  			<td width="100%">
	  				<h4><a href="' . W_ABSPATH . 'community/' . $arrCommunity[$num]['ID_community'] . '"><span style="background:#FCFFCA">' . $arrCommunity[$num]['name'] . '</span></a></h4>
	  			</td>
	  		</tr>
	  		<tr>
	  			<td>
	  				' . $arrCommunity[$num]['description'] . '
	  			</td>
	  		</tr>
	  		<tr>
	  			<td>
	  				Количесво человек(' . $arrCommunity[$num]['quantity'] . ')
	  			</td>
	  		</tr>
	  	</table><br />';
	  }
  }
  
	/**
	 * отображение списка сообществ в упращенном виде
	 */
  public static function displayAllCommunitySimple($arrCommunity){
  	for ($num = 0; $num <sizeof($arrCommunity); $num++){
  		echo '
  		<table id="sideCommunityTable">
				<tr>
					<td colspan="2">
					</td>
					<td align="center">
						<span id="rating">Рейтинг</span>
					</td>
					<td align="center">
						<span id="rating">Количесво участников</span>
					</td>
				</tr>';
					for ($num=0; $num < sizeof($arrCommunity); $num++){
						echo '
						<tr>
							<td class="image">
								<img class="preview" src="' . W_IMAGES . 'icons/playSmallGray.gif' . '"/>
							</td>
							<td class="name">
								<span class="commName"><a href="' . W_ABSPATH . 'community/' . $arrCommunity[$num]['ID_community'] . '" class="none"><b>' . $arrCommunity[$num]['name'] . '</b></a></span>
							</td>
							<td class="membership">
								<div class="divMembership"><div>
									<span class="membership"></span><span class="yellowBg">|</span>
								</div></div>
							</td>
							<td class="membership">
								<div class="divMembership"><div>
									<span class="membership">' . $arrCommunity[$num]['quantity'] . '</span><span class="yellowBg">|</span>
								</div></div>
							</td>
						</tr>
					';
			  	}
				echo '				
			</table>';
  	}
  }
  
  /**
   * функция отображение топов
   */
  public static function communityPage($arrCommunities){
  	echo '<div class="all_community">';
  	foreach ($arrCommunities as $arrCommunities){
  		echo '
  			<div class="community_page">
	  			<div class="community_page_bottom">
		  			<div class="community_page_right">
			  			<div class="community_page_left">
				  			<div class="community_page_right_top">
					  			<div class="community_page_right_bootom">
						  			<div class="community_page_left_bottom">
							  			<div class="community_page_left_top">
												<div class="leftPartC">
													<div class="avaCommC">
														<a href="' . W_ABSPATH . 'community/' . $arrCommunities['ID_folder'] . '"><img alt="" src="' .  W_IMAGES . 'pictures/community/s_' . (isset($arrCommunities['avatar_path']) ? ($arrCommunities['ID_folder'] . '.' . $arrCommunities['avatar_path']) : 'default.gif') . '" height="80" width="80" /></a>
													</div>
													<h4 class="fade" title="' . $arrCommunities['name'] . '"><a href="' . W_ABSPATH . 'community/' . $arrCommunities['ID_folder'] . '">' . $arrCommunities['name'] . '<i class="fade"></i></a></h4></p>
												</div>
												<div class="rightPart">
													<ul>
														<li>Написано комментариев: <a href="' . W_ABSPATH . 'community/' . $arrCommunities['ID_folder'] . '#comments">' . $arrCommunities['comment_amount'] . '</a></li>
														<li>Написано статей: <a href="' . W_ABSPATH . 'articles?idFolder=' . $arrCommunities['ID_folder'] . '">' . $arrCommunities['article_amount'] . '</a></li>
														<li>Добавлено вопросов: <a href="' . W_ABSPATH . 'questions?folder=' . $arrCommunities['ID_folder'] . '&pageNum=1">' . $arrCommunities['question_amount'] . '</a></li>
														<li>Добавлено самоучителей: <a href="' . W_ABSPATH . 'tutorials?idFolder=' . $arrCommunities['ID_folder'] . '&pageNum=1">' . $arrCommunities['tutorial_amount'] . '</a></li>
														<li>Добавлено готовых решений: <a href="' . W_ABSPATH . 'solutions?idFolder=' . $arrCommunities['ID_folder'] . '&pageNum=1">' . $arrCommunities['solution_amount'] . '</a></li>
														<li>Пользователей: <a href="' . W_ABSPATH . 'community/users/' . $arrCommunities['ID_folder'] . '">' . $arrCommunities['users_count'] . '</a></li>
													</ul>
												</div>
							  			</div>
						  			</div>
					  			</div>
				  			</div>
			  			</div>
		  			</div>
	  			</div>
  			</div>';
  	}
  	echo '</div>';
  }  
  
  /**
   * выводит всех пользователей сообщества
   *
   * @param int $idCommunity
   * @param unknown_type $arrUsers
   */
  public static function displayAllUsers($arrUsers){
	  for ($num = 0; isset($arrUsers[$num]['ID_user']); $num++){
		  echo '<p>'; echo $num + 1 . ') '; echo '<a href="' . W_ABSPATH . 'user/' . $arrUsers[$num]['login'] . '/">'
		  . $arrUsers[$num]['login'] . '</a></p>';
	  }
  }
  
  /**
   * получаем поле и направление сортировки
   */
  public static function getSorting($order, $direction){
  	switch ($order){//Определяем поле сортировки
			case 1:
				$sorting['orderField'] = 'quantity'; break;
			case 2:
				$sorting['orderField'] = 'name'; break;
			case 3:
				$sorting['orderField'] = 'average_mark'; break;
			case 4:
				$sorting['orderField'] = 'ID_community'; break;
		 }
			
		if ($order != 2){
			switch ($direction){//Определяем направление сортировки
				case 1:
					$sorting['directionDb'] = 'DESC'; break;
				case 2:
					$sorting['directionDb'] = 'ASC'; break;
			}
		}
		else {
			switch ($direction){//Определяем направление сортировки
				case 1:
					$sorting['directionDb'] = 'ASC'; break;
				case 2:
					$sorting['directionDb'] = 'DESC'; break;
			}
		}
		return $sorting;
  }
  
  /**
   * получаем ссылки для сортировки сообществ
   */
  public static function displayOrderReferences($order, $direction){
		echo '<a href = ' . W_ABSPATH . 'communitys/3/1/1/>';
						if ($order == 3 AND $direction == 1)
							echo '
							<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
						echo '
					</a>
						<span>По средней оценке</span>
					<a href = ' . W_ABSPATH . 'communitys/3/2/1/>';
						if ($order == 3 AND $direction == 2)
							echo '
						<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
						echo '
					</a>';	
						
		echo '<a href = ' . W_ABSPATH . 'communitys/1/1/1/>';
				if ($order == 1 AND $direction == 1)
					echo '
					<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
				else 
					echo '
					<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
				echo '
			</a>
				<span>По популярности</span>
			<a href = ' . W_ABSPATH . 'communitys/1/2/1/>';
				if ($order == 1 AND $direction == 2)
					echo '
				<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
				else 
					echo '
					<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
				echo '
			</a>';
				
		echo '<a href = ' . W_ABSPATH . 'communitys/4/1/1/>';
						if ($order == 4 AND $direction == 1)
							echo '
							<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
						echo '
					</a>
						<span>По дате создания</span>
					<a href = ' . W_ABSPATH . 'communitys/4/2/1/>';
						if ($order == 4 AND $direction == 2)
							echo '
						<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
						echo '
					</a>';	

		echo '<a href = ' . W_ABSPATH . 'communitys/2/1/1/>';
						if ($order == 2 AND $direction == 1)
							echo '
							<img src="' . W_IMAGES . 'icons/downSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/down.gif" alt="">';
						echo '
					</a>
						<span>По названию</span>
					<a href = ' . W_ABSPATH . 'communitys/2/2/1/>';
						if ($order == 2 AND $direction == 2)
							echo '
						<img src="' . W_IMAGES . 'icons/upSelect.gif" alt="">';
						else 
							echo '
							<img src="' . W_IMAGES . 'icons/up.gif" alt="">';
						echo '
					</a>';							
  }
  
  public static function displayCommunityForEdit($idCommunity, $arrDescription){
		echo '
			<div>
				<div class="blueTitle"><div><div><div><div>
					<h1 class="blockName">Редактирование Сообщества ' . $arrDescription['name'] . '</h1>
				</div></div></div></div></div>';			
				  echo '<a href="' . W_ABSPATH . 'community/' .  $idCommunity . '">в сообщество</a><br/>
				  <form method="post" action="' .  W_ABSPATH . 'community/edit/' .  $idCommunity . '" enctype="multipart/form-data">';			    
				    echo '<h3>Аватарка</h3>
				    			
				    	<img src="' . W_IMAGES . 'pictures/community/s_' . (isset($arrDescription['avatar_path']) ? ($idCommunity . '.' . $arrDescription['avatar_path']) : 'default.gif') . '" /><br/>';
				    $objImage = new Form_File('image');
				    echo $objImage->toString();
				    
				    echo '<br />
				    	<input type="submit" name="saveInfoGroup" value="Сохранить" />
				    <input type="hidden" name="community[ID_community]" value="' . $idCommunity . '" />
			    </form>
			</div>';
  }
  
  /**
   * функция отображения формы для создания нового сообщества
   */
  public static function displayFormForNrwCommunity($tags){
	 echo '
	 <form method="post" action="' .  W_ABSPATH . 'community/new">
	 <h3>Теги:</h3>
		 <textarea style="width:500px; height:30px" type="text" name="tags" />' . $tags . '</textarea><br/>
		 <input type="submit" name="saveInfoGrup" value="Сохранить" />
	 </form>';
  }
  
}
?>
